home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / machine / bagman.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  8KB  |  240 lines

  1. /***************************************************************************
  2.  
  3.   machine.c
  4.  
  5.   Functions to emulate general aspects of the machine (RAM, ROM, interrupts,
  6.   I/O ports)
  7.  
  8. ***************************************************************************/
  9.  
  10. #include "driver.h"
  11.  
  12.  
  13. /*Creation date: 98-02-18 */
  14. /*  A few words of comment:
  15. **
  16. **   Whats inside of this file is a PAL16r6 emulator. Maybe someday we will
  17. **need to use it for some other game too. We will need to make it more exact
  18. **then (some of the functionality of this chip IS NOT implemented). However I
  19. **have bought a book about PAL's and I'm able to make it work better.
  20. **                    Jarek Burczynski
  21. **                    s0246@goblin.pjwstk.waw.pl
  22. */
  23.  
  24. unsigned char andmap[64];
  25. /*table holds outputs of all AND's (after AND map)*/
  26.  
  27. unsigned char columnvalue[32];
  28. /*table holds inputs (ie. not x, x, not q, q) to the AND map*/
  29.  
  30. unsigned char outvalue[8];
  31. /*8 output pins*/
  32.  
  33. unsigned char fusemap[64*32]=
  34. {
  35. /*        64 rows x 32 columns
  36. **  1 - fuse blown (disconnected from input (equal to 1) )
  37. **  0 - fuse not blown (connected to input (ie. not x, x, not q, q accordingly)
  38. */
  39. 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  40. 1,1,1,1,1,1,0,1,1,1,1,0,1,1,0,1,1,1,1,0,1,1,0,1,1,1,0,1,1,1,1,1,
  41. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  42. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  43. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  44. 0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
  108. unsigned short rowoffs;
  109. unsigned char row, column, val;
  110.  
  111. /*count all rows AND's*/
  112.     for (row=0; row<64; row++)
  113.     {
  114.         rowoffs = row<<5;
  115.         val = 1; /*prepare for AND */
  116.         for (column=0; column<32; column++)
  117.         {
  118.             if ( fusemap[ rowoffs + column ] == 0 )
  119.                 val &= columnvalue[column];
  120.         }
  121.         andmap[row] = val;
  122.     }
  123.  
  124. /* I/O pin #19 */
  125.     val=0; /*prepare for OR*/
  126.     for (row=1; row<8; row++)
  127.         val |= andmap[row];
  128.     if (andmap[0]==1)
  129.     {
  130.         columnvalue[2]=1-val;
  131.         columnvalue[3]=val;
  132.         outvalue[0]=1-val;
  133.     }
  134.     else
  135.     {
  136.         //pin is in INPUT configuration so it doesn't create output...
  137.         columnvalue[2]=0;
  138.         columnvalue[3]=1;
  139.     }
  140.  
  141. /* O pin #18 (D1) */
  142.     val=0; /*prepare for OR*/
  143.     for (row=8; row<16; row++)
  144.         val |= andmap[row];
  145.     columnvalue[6]=1-val;
  146.     columnvalue[7]=val;
  147.     outvalue[1]=1-val;
  148.  
  149. /* O pin #17 (D2) */
  150.     val=0; /*prepare for OR*/
  151.     for (row=16; row<24; row++)
  152.         val |= andmap[row];
  153.     columnvalue[10]=1-val;
  154.     columnvalue[11]=val;
  155.     outvalue[2]=1-val;
  156.  
  157. /* O pin #16 (D3) */
  158.     val=0; /*prepare for OR*/
  159.     for (row=24; row<32; row++)
  160.         val |= andmap[row];
  161.     columnvalue[14]=1-val;
  162.     columnvalue[15]=val;
  163.     outvalue[3]=1-val;
  164.  
  165. /* O pin #15 (D4) */
  166.     val=0; /*prepare for OR*/
  167.     for (row=32; row<40; row++)
  168.         val |= andmap[row];
  169.     columnvalue[18]=1-val;
  170.     columnvalue[19]=val;
  171.     outvalue[4]=1-val;
  172.  
  173. /* O pin #14 (D5) */
  174.     val=0; /*prepare for OR*/
  175.     for (row=40; row<48; row++)
  176.         val |= andmap[row];
  177.     columnvalue[22]=1-val;
  178.     columnvalue[23]=val;
  179.     outvalue[5]=1-val;
  180.  
  181. /* O pin #13 (D6) */
  182.     val=0; /*prepare for OR*/
  183.     for (row=48; row<56; row++)
  184.         val |= andmap[row];
  185.     columnvalue[26]=1-val;
  186.     columnvalue[27]=val;
  187.     outvalue[6]=1-val;
  188.  
  189. /* I/O pin #12 */
  190.     val=0; /*prepare for OR*/
  191.     for (row=57; row<64; row++)
  192.         val |= andmap[row];
  193.     if (andmap[56]==1)
  194.     {
  195.         columnvalue[30]=1-val;
  196.         columnvalue[31]=val;
  197.         outvalue[7]=1-val;
  198.     }
  199.     else
  200.     {
  201.         //pin is in INPUT configuration so it doesn't create output...
  202.         columnvalue[30]=0;
  203.         columnvalue[31]=1;
  204.     }
  205.  
  206. }
  207.  
  208. WRITE_HANDLER( bagman_pal16r6_w )
  209. {
  210. unsigned char line;
  211.  
  212.     line = offset<<2;
  213.     columnvalue[line] = 1-(data&1);
  214.     columnvalue[line+1] = data&1;
  215. }
  216.  
  217. void bagman_machine_init(void)
  218. {
  219.     bagman_pal16r6_w(0,1);
  220.     bagman_pal16r6_w(1,1);
  221.     bagman_pal16r6_w(2,1);
  222.     bagman_pal16r6_w(3,1);
  223.     bagman_pal16r6_w(4,1);
  224.     bagman_pal16r6_w(5,1);
  225.     bagman_pal16r6_w(6,1);
  226.     bagman_pal16r6_w(7,1);
  227.     update_pal();
  228. }
  229.  
  230. READ_HANDLER( bagman_pal16r6_r )
  231. {
  232.     update_pal();
  233.     return    (outvalue[6]) + (outvalue[5]<<1) + (outvalue[4]<<2) +
  234.         (outvalue[3]<<3) + (outvalue[2]<<4) + (outvalue[1]<<5);
  235.  
  236. /* Notice that I haven't had Bagman schematics so this is my attemp to guess
  237. what pin is connected to what bit in this address (a000), however it seems to
  238. work.*/
  239. }
  240.